import time

from selenium.webdriver.common.by import By

from Driver.Driver import Blogdriver

class BlogPage:
    driver=''
    url=''

    def __init__(self):
        self.driver=Blogdriver.driver
        self.url="http://8.137.19.140:9090/blog_list.html"
        self.driver.implicitly_wait(2)

    # 未登陆时直接进入界面
    def NoLogIn(self):
        self.driver.get(self.url)
    # 登陆后进入界面
    def LogIn(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhangsan")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys(123456)
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()

    # 节省编写时间的函数
    def Qtest(self,key):
        self.driver.find_element(By.CSS_SELECTOR, key)
    # 测试博客界面
    def BlogAticle(self):
        # 测试是否存在标题
        self.Qtest("body > div.container > div.right > div:nth-child(1) > div.title")
        # 测试是否存在时间
        self.Qtest("body > div.container > div.right > div:nth-child(1) > div.date")
        # 测试是否存在内容文本
        self.Qtest("body > div.container > div.right > div:nth-child(1) > div.desc")
        # 测试是否存在名称
        self.Qtest("body > div.container > div.left > div > h3")
        # 测试是否存在头像
        self.Qtest("body > div.container > div.left > div > img")
        # 测试是否存在GIthub地址
        self.Qtest("body > div.container > div.left > div > a")
        # 测试是否存在博客栏的内容
        self.Qtest("body > div.nav > a:nth-child(4)")
        self.Qtest("body > div.nav > a:nth-child(5)")
        self.Qtest("body > div.nav > a:nth-child(6)")
        # 测试是否存在文章、分类及数字显示
        self.Qtest("body > div.container > div.left > div > div:nth-child(4) > span:nth-child(1)")
        self.Qtest("body > div.container > div.left > div > div:nth-child(4) > span:nth-child(2)")
        self.Qtest("body > div.container > div.left > div > div:nth-child(5) > span:nth-child(1)")
        self.Qtest("body > div.container > div.left > div > div:nth-child(5) > span:nth-child(2)")
        Blogdriver.getscreen()

    # 点击“查看全文”跳转博客详情页
    def GoToBlogDetail(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > a").click()
        Blogdriver.getscreen()

    #点击Github地址跳转
    def GotoGitHub(self):
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > a").click()
        Blogdriver.getscreen()



    #博客主界面博客列表
    # 点击主页
    def titlebarHome(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(4)").click()
        Blogdriver.getscreen()


    # 点击编辑页
    def titlebarCreate(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(5)").click()
        Blogdriver.getscreen()


    # 点击注销
    def titlebarOut(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(6)").click()
        Blogdriver.getscreen()
